import { Course, CourseDetail } from '../models/course.model';
import { courses } from '../mock/course.mock';

export class CourseService {
    async getCourses(): Promise<Course[]> {
        return courses;
    }

    async getCourseById(id: number): Promise<CourseDetail | null> {
        return courses.find(course => course.id === id) || null;
    }

    async searchCourses(query: string): Promise<Course[]> {
        const lowercaseQuery = query.toLowerCase();
        return courses.filter(course => 
            course.title.toLowerCase().includes(lowercaseQuery) ||
            course.description.toLowerCase().includes(lowercaseQuery) ||
            course.tags.some(tag => tag.toLowerCase().includes(lowercaseQuery))
        );
    }

    async toggleFavorite(userId: number, courseId: number): Promise<boolean> {
        // 这里模拟收藏功能，实际应该有收藏表
        return true;
    }
}
